<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>社区-关注</title>
		<script src="js/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="fonts/iconfont.css"/>
		<link rel="stylesheet" type="text/css" href="css/base.css"/>
		<link rel="stylesheet" type="text/css" href="css/master.css"/>
		
		
		<script src="js/rem.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		
		
		
		
		<script type="text/javascript">
			let n1=new Date()
			console.log(n1.getTime())
			window.onload=function(){
				let focusAddApi='http://15637237221.wicp.vip/yh/Bbs/followHotUser.do'
				let focuscancelApi='http://15637237221.wicp.vip/yh/Bbs/unfollowHotUser.do'
				let token=localStorage.getItem('token')
				let userThemeApi='http://15637237221.wicp.vip/yh/Bbs/findFollowUserTheme.do'
				let teacherListApi='http://15637237221.wicp.vip/yh/Bbs/findGoldenUserForTch.do'
				//名师推荐请求
				let teacherList=document.querySelector('.focus-teacherlist')
				axios.post(teacherListApi,{
					token
				}).then(res=>{
					console.log(res.data.info)
					let html=''
					let arr=res.data.info;
					for(let i = 0;i<arr.length;i++){
						html+=`
						<li>
								<a href="javascript:;" selfId='${arr[i].userId}'>
									<em class="iconfont icon-add-fill"></em>
									<div class="teacher-pic-wrap">
									<img src="${arr[i].userImgUrl}">
									</div>
									<p>${arr[i].username}</p>
									<span>${arr[i].userType.userTypeName}</span>
								</a>
						</li>
						`
					}
					teacherList.innerHTML=html;
					let btns=document.querySelectorAll('.focus-teacherlist a');
					let shows = document.querySelectorAll('.focus-teacherlist em')
					console.log(btns)
						
					for(let i = 0;i<btns.length;i++){
						btns[i].onclick=function(){
							if(token){
								let followId=this.getAttribute('selfId')
							let userFollowApi='http://15637237221.wicp.vip/yh/mine/followUser.do'
							axios.post(userFollowApi,{token}).then(res=>{
								console.log(res.data.info)
								let arr = res.data.info
								let targetObj=arr.find(v=>v.id==followId)
								if(targetObj){
										console.log(targetObj)
										shows[i].classList.remove('icon-duihao')
										shows[i].classList.add('icon-add-fill')
										axios.post(focuscancelApi,{
											token,followId
										}).then(res=>{
											console.log(res)
											alert(res.data.info)
											location.reload()
										})
									
								}else{
									shows[i].classList.remove('icon-add-fill')
									shows[i].classList.add('icon-duihao');
									axios.post(focusAddApi,{
										token,followId
									}).then(res=>{
										console.log(res)
										alert(res.data.info)
										location.reload()
									})
								}
							})
							}else{
							alert('请登录')
							location.href='login.html'
							}
							
							
							
						}
					}
				})
				//最新发布请求
				axios.post(userThemeApi,{
					token
				}).then(res=>{
					let list=document.querySelector('.focus-con')
					console.log(res.data.info)
					let arr=res.data.info;
					let html=''
					console.log(arr[0].type)
					for(let i = 0;i<arr.length;i++){
						html+=`
						<div class="focus-con-main">
						<figure>
							<img src="${arr[i].user.userImgUrl}" >
							<figcaption>
								<p>${arr[i].user.username}</p>
								
								<span class="timeSpan">${(arr[i].uploadTime)}</span>
							</figcaption>
						</figure>
						<img src="${arr[i].imgUrl}" >
						</div>
						
						`
					}
					list.innerHTML=html
					let timeSpans=document.querySelectorAll('.timeSpan')
					console.log(timeSpans)
					for(let i= 0;i<timeSpans.length;i++){
						
						let time=timeSpans[i].innerHTML
						console.log(time)
						let n1 = new Date(time)
						console.log(n1)
						let y1 = n1.getFullYear()
						console.log(y1)
						let month = n1.getMonth()+1
						console.log(month)
						let day = n1.getDay()
						console.log(day)
						let html=`${y1}-${month}-${day}`
						timeSpans[i].innerHTML=html
						
					}
				})
				
				
				nowSend.onclick=function(){
					let nowSendApi='http://15637237221.wicp.vip/yh/Bbs/addTheme.do'
					axios.post(nowSendApi,{
						token
					}).then(res=>{
						console.log(res)
					})
				}
			
			}
			
			
		</script>
		<div class="container">
			<!-- header -->
			<header id="community-tit">
				<img src="img/top.png" class="zhuangtailan">
				<ul>
					<li>
						<a href="community-focus.1.html" class="community-focus community-spec">关注</a>
					</li>
					<li>
						<a href="community-find.html"  class="community-find">发现</a>
					</li>
					<li>
						<a href="search.html" class="iconfont icon-search"></a>
					</li>
				</ul>
			</header>
			
			<!-- main -->
			<main>
				
				<div class="meet-tit"><em class="meet-left"></em>推荐老师—让艺术改变生活</div>
				<ul class="focus-teacherlist">
				<!-- 	<li>
						<a href="javascript:;">
							<em class="iconfont icon-add-fill"></em>
							<img src="img/黄华三.png" alt="">
							<p>黄华三</p>
							<span>中国人民大学教授</span>
						</a>
					</li>
					<li>
						<a href="javascript:;">
							<em class="iconfont icon-add-fill"></em>
							<img src="img/施本铭.png" alt="">
							<p>黄华三</p>
							<span>中国人民大学教授</span>
						</a>
					</li>
					<li>
						<a href="javascript:;">
							<em class="iconfont icon-add-fill"></em>
							<img src="img/黄华三.png" alt="">
							<p>黄华三</p>
							<span>中国人民大学教授</span>
						</a>
					</li>
					<li>
						<a href="javascript:;">
							<em class="iconfont icon-add-fill"></em>
							<img src="img/黄华三.png" alt="">
							<p>黄华三</p>
							<span>中国人民大学教授</span>
						</a>
					</li> -->
				</ul>
				<div class="focus-pic">
					<a href="javascript:;" id="nowSend"><img src="img/golden.png" ></a>
					
				</div>
				
				<div class="meet-tit"><em class="meet-left"></em>New 最新发布</div>
				<div class="focus-con">
					<!-- <div class="focus-con-main">
					<figure>
						<img src="img/李魁正.png" >
						<figcaption>
							<p>李魁正</p>
							
							<span>2019-03-18</span>
						</figcaption>
					</figure>
					<img src="img/focus.png" >	
					</div>
					
					<div class="focus-con-main">
					<figure>
						<img src="img/李魁正.png" >
						<figcaption>
							<p>李魁正</p>
							
							<span>2019-03-18</span>
						</figcaption>
					</figure>
					<img src="img/focus.png" >	
					</div> -->
					
				</div>
			</main>
			
			<!-- footer -->
			<footer>
				<a href="index-rec.html">
										<span class="iconfont icon-shouye
				"></span>
										<p>首页</p>
									</a>
									
									<a href="meet.html">
										<span class="iconfont icon-tupian
				"></span>
										<p>遇见</p>
									</a>
									
									<a href="community-focus.1.html ">
										<span class="iconfont icon-shequ-weijihuo" style="color:#EEC14F ;"></span>
										<p style="color:#EEC14F ;">社区</p>
									</a>
									
									<a href="selfcenter.html">
										<span class="iconfont icon-wode"></span>
										<p>我的</p>
									</a>
			</footer>
		</div>
	</body>
</html>
